﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using PowerPoint = Microsoft.Office.Interop.PowerPoint;
using Microsoft.Office.Core;

namespace Server
{
    class ServerPPTControl
    {
        private string pptPtah;
        private int slidesCount;//总幻灯片数
        private int showPosition;//当先在第showPosition张幻灯片
        private PowerPoint.Application application;
        private PowerPoint.Presentation presentation;
        private PowerPoint.SlideShowWindow slideShowWindow;
        private PowerPoint.SlideShowView slideShowView;

        public ServerPPTControl(String filePath)
        {
            pptPtah = filePath.Replace(@"\", @"\\");
            application = new PowerPoint.Application();
            
        }

        public int SlidesCount
        {
            get
            {
                return slidesCount;
            }
            set
            {
                slidesCount = value;
            }
        }

        public int ShowPosition
        {
            get
            {
                return showPosition;
            }
            set
            {
                showPosition = value;
            }
        }

        public void setSlideShowBeginEventHandler(PowerPoint.EApplication_SlideShowBeginEventHandler slideShowBeginEventHandler)
        {
            application.SlideShowBegin += slideShowBeginEventHandler;
        }

        public void setSlideShowNextSlideEventHandler(PowerPoint.EApplication_SlideShowNextSlideEventHandler slideShowNextSlideEventHandler)
        {
            application.SlideShowNextSlide += slideShowNextSlideEventHandler;

        }

        public void setSlideShowEndEventHandler(PowerPoint.EApplication_SlideShowEndEventHandler slideShowEndEventHandler)
        {
            application.SlideShowEnd += slideShowEndEventHandler;

        }

        public void start()
        {
            application.Visible = MsoTriState.msoTrue;
            presentation = application.Presentations.Open(pptPtah);
            presentation.SlideShowSettings.Run();

            slideShowWindow = presentation.SlideShowWindow;
            slideShowView = slideShowWindow.View;
        }

        public void next()
        {
            slideShowView.Next();
        }

        public void previous()
        {
            slideShowView.Previous();
        }

        public void close()
        {
            if (presentation != null)
            {
                presentation.Close();
                presentation = null;
            }
            if (application != null)
            {
                application.Quit();
                application = null;
            }
        }


        //private string note;//当前页的备注信息
        //note = Wn.Presentation.Slides[showPosition].NotesPage.Shapes.Placeholders[2].TextFrame.TextRange.Text;

    }
}
